﻿using System.Collections.Generic;
using Core.ProcessManager.Messenger;
using Core.ProcessManager.Process;
using Core.ProcessManager.ProcessLoader;

namespace Core.ProcessManager
{
    public class ProcessPerformer
    {
        private readonly IMessenger _messenger;
        private readonly IProcessLoader _processLoader;
        private readonly List<IProcess> _processes;

        public List<IProcess> Processes
        {
            get { return _processes; }
        }

        public ProcessPerformer(IMessenger messenger, IProcessLoader processLoader)
        {
            _messenger = messenger;
            _processLoader = processLoader;

            _processes = new List<IProcess>();
        }

        public bool IsValid
        {
            get { return _processes.Count > 0; }
        }

        public void ExecuteProcesses()
        {
            foreach (var process in _processes)
            {
                process.StartProcess(_messenger);
            }
        }

        public void LoadProcesses()
        {
            _processes.AddRange(_processLoader.LoadAll());
        }
    }
}